package com.yanqu.road.server.cmd.specialserver;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.specialserver.IceServerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.specialserver.IceServerModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ICE_SERVER_UNLOCK_BUILD, desc = "解锁建筑物")
public class IceServerUnlockBuildCmd extends AbstractCommand {

    private long sliverNum;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        IceServerProto.IceServerUnlockBuildReqMsg reqMsg = IceServerProto.IceServerUnlockBuildReqMsg.parseFrom(packet.getBytes());
        sliverNum = reqMsg.getSliverNum();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(IceServerModule.class).unlockBuild(sliverNum);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            IceServerProto.IceServerUnlockBuildRespMsg.Builder respMsg = IceServerProto.IceServerUnlockBuildRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.S_ICE_SERVER_UNLOCK_BUILD % 20000, respMsg);
        }
    }
}
